package com.minotauro.bean.property;

import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;

@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class AnnotationProcessor extends AbstractProcessor {

  private boolean isCledaBean;

  private Trees trees;

  // --------------------------------------------------------------------------------

  public boolean getIsCledaBean() {
    return isCledaBean;
  }

  // --------------------------------------------------------------------------------

  public AnnotationProcessor() {
    // Empty
  }

  // --------------------------------------------------------------------------------

  @Override
  public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    trees = Trees.instance(processingEnv);
  }

  // --------------------------------------------------------------------------------

  @Override
  public boolean process( //
      Set<? extends TypeElement> annotations, //
      RoundEnvironment roundEnvironment) {

    AnnotationTreeVisitor visitor = new AnnotationTreeVisitor();

    
    for (Element element : roundEnvironment.getRootElements()) {
      TreePath treePath = trees.getPath(element);
      visitor.scan(treePath, trees);

      isCledaBean = visitor.getIsCledaBean();
    }
    return true;
  }
}
